package org.eduapp.trains.dao.option.impl;

import java.util.List;

import org.eduapp.trains.DAOException;
import org.eduapp.trains.dao.BaseDAOImpl;
import org.eduapp.trains.dao.option.OptionDAO;
import org.eduapp.trains.model.options.ModelOptions;
import org.eduapp.trains.model.order.ModelOrder;
import org.eduapp.trains.utils.UtilsString;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

/**
 * 
 * @author jeccy
 *
 */
public class OptionDAOImpl extends BaseDAOImpl<ModelOptions> implements OptionDAO {

	@SuppressWarnings("unchecked")
	@Override
	public List<ModelOptions> getByName(String optionName) throws DAOException {
		
		DetachedCriteria criteria = DetachedCriteria.forClass(ModelOrder.class);
		
		if (UtilsString.isNotEmpty(optionName)) {
			criteria.add(Restrictions.eq("optionName", optionName));
		}
		
		return (List<ModelOptions>)getListByCriteria(criteria);
	}

}
